onFenixReady(function() {
    video = document.getElementById("video");
    cts = document.querySelector(".relative-content");
    played = false

    video.addEventListener("timeupdate", function(e) {
        if (video.currentTime > 5) {
            video.pause();
            sendEvent("video_ended");
        }
    });

    video.addEventListener("click", function() {
        sendEvent("click_to_site");
    });

    cts.addEventListener("click", function() {
        onClick()
    })



    function onClick() {
        // feature detect
        if (typeof DeviceOrientationEvent.requestPermission === 'function') {
            DeviceOrientationEvent.requestPermission()
                .then(permissionState => {
                    if (permissionState === 'granted') {
                        window.addEventListener('deviceorientation', (e) => {
                            var x = e.beta; // In degree in the range [-180,180]
                            var y = e.gamma; // In degree in the range [-90,90]
                            if (e.gamma > 30) {
                                // upside down ish
                                document.querySelector("#video").play();
                                if (!played) {
                                    sendEvent("tilt_play");
                                    played = true
                                }
                            } else {}

                        });
                    }
                })
                .catch(console.error);
        } else {

        }
    }

                function handleOrientation(event) {
                var x = event.beta; // In degree in the range [-180,180]
                var y = event.gamma; // In degree in the range [-90,90]
                if (event.gamma > 30) {
                    document.querySelector("#video").play();
                    if (!played) {
                        sendEvent("tilt_play");
                        played = true
                    }

                }

            }
            window.addEventListener("deviceorientation", handleOrientation);



    setTimeout(function() {
        document.querySelector(".relative-content").style.display = "none";
    }, 3000);
});